
package Purl::Template;
use strict;

require Exporter;
our @ISA    = qw(Exporter);
our @EXPORT = qw(processTemplate);

use Purl::Config; 
use Template::Alloy;

#my $sn = config("servername");
#print STDERR "SN: ---$sn---\n";
# Create a new Template object, with the default path, and any configured and passed paths.
my $_templates
    = new Template::Alloy( INCLUDE_PATH => [ 'txt/templates', config("mushdir") . "/" . config("templatedir")] );

sub processTemplate {
    my %args = @_;
    my $r;
    # Set some basics.
    $args{MUSHName} = config("servername");
   # foreach $r ( keys %args ) { print "$r -> $args{$r}\n"; }
    my $returnString;
    my $templateFile;    
    print STDERR "WARN: Attempt to process blank template. $args{template} \n"
        if ( !$args{template} );

    $templateFile = $args{template} . '.tt';
    $_templates->process( $templateFile, \%args, \$returnString );

    return $returnString;
}

